home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / edct9401.zip / esplit.c < prev    next >
C/C++ Source or Header  |  1994-01-27  |  2KB  |  112 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. #define TRUE 1
  6. #define FALSE 0
  7.  
  8. long int lno=0;
  9. FILE *fi,*fo1,*fo2,*fopen();
  10. unsigned char *ptr,*wds,*front,*means[100],*tests[100],instr[512];
  11.  
  12. int notests,nostr,j,f1act,f2act,i;
  13.  
  14. main(argc,argv)
  15. int argc;
  16. char **argv;
  17. {
  18.     int argk;
  19.     register char **p;
  20.     argk = argc;
  21.     if (argk < 3)
  22.     {
  23.         printf("usage: esplit fni fno-dict fno-names\n\n ");
  24.         printf("ESPLIT takes as its input an _edict_ Japanese Dictionary file\n ");
  25.         printf("and produces from it two files; one containing _proper-name_\n ");
  26.         printf("entries, and the other _normal_ entries.\n\n ");
  27.         printf("   fni - input file name\n ");
  28.         printf("   fno-dict - output file for normal entries\n ");
  29.         printf("   fno-names - output file for proper-name entries\n ");
  30.         exit(0);
  31.     }
  32.     p=argv;
  33.     p++;
  34.     --argk;
  35.     fi= fopen(*p,"r");
  36.     if (fi == NULL)
  37.     {
  38.         printf("\nCannot open %s\n",*p);
  39.         exit(0);
  40.     }
  41.     p++;
  42.     fo1 = fopen(*p,"w");
  43.     if(fo1 == NULL)
  44.     {
  45.         printf("open of %s failed\n",*p);
  46.         exit(0);
  47.     }
  48.     p++;
  49.     fo2 = fopen(*p,"w");
  50.     if(fo2 == NULL)
  51.     {
  52.         printf("open of %s failed\n",*p);
  53.         exit(0);
  54.     }
  55.     wds = (unsigned char *)"pn) pn, pl) pl,";
  56.     ptr = (unsigned char *)strtok(wds," ");
  57.     for(notests = 0;notests<100;notests++)
  58.     {
  59.         tests[notests] = ptr;
  60.         ptr = (unsigned char *)strtok(NULL," ");
  61.         if(ptr == NULL) break;
  62.     }
  63.  
  64.     while (feof(fi) != TRUE)
  65.     {
  66.         fgets (instr,511,fi);
  67.         if(feof(fi)) break;
  68.         if((++lno % 10) == 0)printf("Line: %ld\r",lno);
  69.         if(instr[strlen(instr)-1] < 0x20) instr[strlen(instr)-1] = 0;
  70.         front = (unsigned char *)strtok(instr,"/");
  71.         ptr = (unsigned char *)strtok(NULL,"/");
  72.         for(nostr = 0;nostr<100;nostr++)
  73.         {
  74.             means[nostr] = ptr;
  75.             ptr = (unsigned char *)strtok(NULL,"/");
  76.             if (ptr == NULL) break;
  77.         }
  78.         f1act = FALSE;
  79.         f2act = FALSE;
  80.         for(i=0;i<=nostr;i++)
  81.         {
  82.             for(j=0;j<=notests;j++)
  83.             {
  84.                 if(strstr(means[i],tests[j]) != NULL)
  85.                 {
  86.                     if(!f2act)
  87.                     {
  88.                         f2act = TRUE;
  89.                         fprintf(fo2,"%s/",front);
  90.                     }
  91.                     fprintf(fo2,"%s/",means[i]);
  92.                     break;
  93.                 }
  94.                 if(j == notests)
  95.                 {
  96.                     if(!f1act)
  97.                     {
  98.                         f1act = TRUE;
  99.                         fprintf(fo1,"%s/",front);
  100.                     }
  101.                     fprintf(fo1,"%s/",means[i]);
  102.                 }
  103.             }
  104.         }
  105.         if(f1act) fprintf(fo1,"\n");
  106.         if(f2act) fprintf(fo2,"\n");
  107.     }
  108.     fclose(fi);
  109.     fclose(fo1);
  110.     fclose(fo2);
  111. }
  112.